# Quick guide

# Pulls the official image. The command pulls the tomcat image with jdk8-corretto tag. The default tag is latest.
# docker pull tomcat:jdk8-corretto

# Runs tomcat image.
# docker run -d --restart always -p 8080:8080 --name=my-tomcat -v d:\my-tomcat-container-home:/home tomcat:jdk8-corretto

# Lists running containers.
# docker ps

# Runs terminal in the container.
# docker exec -it [container-id-can-get-from-last-step] bash

# End of quick guide 

# Uses the official image as a parent image.
FROM tomcat:9.0.91-jre17

# Copies the war file to the tomcat webapps directory.
# The path depends on the context path which is where you run the command.
# IMPORTANT. The file out of the context cannot be accessed. That means you cannot run the command in docker fold. '../bind/' path likes this will be unreachable.
COPY ./grails/family-expense-api/build/libs/family-expense-api.war /usr/local/tomcat/webapps

# Copies the tomcat config file to the tomcat webapps/conf directory.
# If you want to overwrite any config you can copy the file as you need.
# COPY ./docker/server.xml /usr/local/tomcat/conf

# Tomcat starts slowly in docker container. This solves this issue.
RUN export JAVA_OPTS=-Djava.security.egd=file:/dev/urandom

# Changes the container's default UTC timezone to GMT+8.
RUN cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
RUN echo "Asia/Shanghai" > /etc/timezone

# Builds the image.
# The defalut tag is latest. You can define any you need. Example: family-expense-api:1.0
# The -f specifies the Dockerfile path. With this argument we can run build command out of docker file directory. This makes the parent directory of docker file directory the execution context.
# docker build --tag family-expense-api:9.0.91 -f .\docker\grails-family-expense-api\Dockerfile .

# Runs the image.
# The defalut tag is latest. You can define any you need. Example: family-expense-api:1.0
# The --restart always defines the restart policy. Always restart the container if it stops. If it is manually stopped, it is restarted only when Docker daemon restarts or the container itself is manually restarted.
# The -p 8080:8080 defines the port mapping between host and container.
# The -v d:\family-expense-api-home:/home defines mapping directory between host and container.
# docker run -d --restart always -p 8080:8080 --name=family-expense-api:9.0.91 -v d:\family-expense-api-home:/home family-expense-api

# Lists running containers.
# docker ps

# Runs terminal in the container.
# docker exec -it [container-id-can-get-from-last-step] bash

# Saves the image to a local file.
# The defalut tag is latest. You can define any you need. Example: family-expense-api:1.0
# docker save -o d:\family-expense-api-9.0.91.tar family-expense-api:9.0.91

# Loads the local image file
# docker load -i d:\family-expense-api-9.0.91.tar

# Runs MySQL image
# The -e MYSQL_ROOT_PASSWORD=12344321 sets the defalut password for root user.
# The -v d:\family-expense-mysql-home:/var/lib/mysql maps the mysql diectory to the host. This can make sure all database infos remain even this container is deleted.
# docker run --name family-expense-mysql -e MYSQL_ROOT_PASSWORD=12344321 -d -p 3306:3306 -v d:\family-expense-mysql-home:/var/lib/mysql mysql

# More info check on https://docs.docker.com/